﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Skywave.Security
{
    public class PolicyValueList
    {
        public PolicyValueList()
        {
        }
        public PolicyValueList(string valueInString)
        {
            Value = valueInString;
        }

        /// <summary>
        /// Value Property
        /// </summary>
        public string Value
        {
            get { return _Value; }
            set { _Value = value; LoadFromString(); }
        }
        private string _Value;

        /// <summary>
        /// ListOfValues Property
        /// </summary>
        public List<string> ListOfValues
        {
            get { return _ListOfValues; }
            set { _ListOfValues = value; }
        }
        private List<string> _ListOfValues = new List<string>();

        Regex regex1 = new Regex(@"[$](?<value>[^$]*)[$]");
        public void LoadFromString()
        {
            _ListOfValues.Clear();
            if (_Value != null && _Value != "")
            {
                foreach (Match fe1 in regex1.Matches(_Value))
                {
                    _ListOfValues.Add(fe1.Groups["value"].Value);
                }
            }
        }

        public void GenerateValue()
        {
            _Value = "";
            foreach (string fe1 in _ListOfValues)
            {
                _Value += "$" + fe1 + "$";
            }
        }
    }
}
